<?php
namespace app\modules\api\controllers;

use yii;
use app\modules\api\service\CustomerService;
use app\modules\api\service\InquiryService;

class SettingController extends BaseController
{
    public $enableCsrfValidation = false;

    /**
     * 客户列表
     */
    public function actionCustomer_list()
    {
        $p = yii::$app->request->post('p')??1;
        $s = yii::$app->request->post('s')??15;
        $where = [];
        $where['customer_name']   = yii::$app->request->post('customer_name');
        $where['customer_group']  = yii::$app->request->post('customer_group');
        $where['refer']           = yii::$app->request->post('refer');
        $where['follow_man']      = yii::$app->request->post('follow_man');
        $where['customer_status'] = yii::$app->request->post('customer_status');
        $where['property']        = yii::$app->request->post('property');
        $service = new CustomerService();
        $list = $service->list($p, $s, $where);
        return json_encode($list);
    }

    /**
     * 客户列表size
     */
    public function actionCustomer_size()
    {
        $where = [];
        $where['customer_name']   = yii::$app->request->post('customer_name');
        $where['customer_group']  = yii::$app->request->post('customer_group');
        $where['refer']           = yii::$app->request->post('refer');
        $where['follow_man']      = yii::$app->request->post('follow_man');
        $where['customer_status'] = yii::$app->request->post('customer_status');
        $where['property']        = yii::$app->request->post('property');
        $service = new CustomerService();
        $size = $service->size($where);
        return json_encode(['code'=>1,'size'=>$size]);
    }

    /**
     * 询盘管理列表
     */
    public function actionInquiry_list()
    {
        $p = yii::$app->request->post('p')??1;
        $s = yii::$app->request->post('s')??15;
        $where = [];
        $where['begin_time']     = yii::$app->request->post('begin_time');
        $where['end_time']       = yii::$app->request->post('end_time');
        $where['star']           = yii::$app->request->post('star');
        $where['recommend']      = yii::$app->request->post('recommend');
        $where['status']         = yii::$app->request->post('status');
        $where['property']       = yii::$app->request->post('property');
        $where['service_name']   = yii::$app->request->post('service_name');
        $where['name']           = yii::$app->request->post('name');
        $where['email']          = yii::$app->request->post('email');
        $where['inquiry_detail'] = yii::$app->request->post('inquiry_detail');

        $service = new InquiryService();
        $list = $service->list($p,$s,$where);
        return json_encode($list);
    }

    /**
     * 询盘管理列表size
     */
    public function actionInquiry_size()
    {
        $where = [];
        $where['begin_time']     = yii::$app->request->post('begin_time');
        $where['end_time']       = yii::$app->request->post('end_time');
        $where['star']           = yii::$app->request->post('star');
        $where['recommend']      = yii::$app->request->post('recommend');
        $where['status']         = yii::$app->request->post('status');
        $where['property']       = yii::$app->request->post('property');
        $where['service_name']   = yii::$app->request->post('service_name');
        $where['name']           = yii::$app->request->post('name');
        $where['email']          = yii::$app->request->post('email');
        $where['inquiry_detail'] = yii::$app->request->post('inquiry_detail');
        
        $service = new InquiryService();
        $size = $service->size($where);

        return json_encode(['code'=>1,'size'=>$size]);
    }
}
